#include "filereadutil.h"
#include <QFile>
#include <QIODevice>
#include <QDebug>


FileReadUtil::FileReadUtil(QObject *parent) : QObject(parent)
{

}

QString  FileReadUtil::readAll(const QString&path){
    QString data ;
    QFile file(path);
    if(file.open(QIODevice::ReadOnly)){
        data =file.readAll();
        file.close();
    }
    return data;
}

QStringList FileReadUtil::readFile(const QString& path){
    QString data ;
    QFile file(path);
    if(file.open(QIODevice::ReadOnly)){
        data =file.readAll();
        file.close();
    }
    QStringList files ;
    if(!data.isEmpty()){
        QStringList fds =   data.split("}{");

        if(fds.length()==1){
            files.append(fds[0]);
            return files;
        }
        for(int i=0;i<fds.length();i++) {
            if(i==0){
                QString items(fds[i]);
                items.append("}");
                files.append(items);
                continue;
            }
            if(i==fds.length()-1){
                QString nitems("{");
                nitems.append(fds[i]);
                files.append(nitems);
                continue;
            }
            QString nitems("{");
            nitems.append(fds[i]);
            nitems.append("}");
            files.append(nitems);

        }


    }

    return files;
}
